<template>
	<view class="wraps" @click="godetails">
		<view class="news" v-if="content.cover_type !== 3">
			<view class="news_text">
				<view class="news_title">{{content.title}}</view>
				<view class="fu_title" v-if="content.description">{{content.description}}</view>
				<view class="small_text" style="color: #ccc;">
					<view style="display: flex;align-items: center;">
						<view class="time">{{content.format_date}}</view>
						<view class="looks">
							<u-icon name="eye" size="26"></u-icon>
							<text style="margin-left: 5px;">{{content.clicks}}</text>
						</view>
					</view>
					<view class="author">{{content.author?content.author:''}}</view>
				</view>
			</view>
			<image :src="content.cover" mode="aspectFill" v-if="content.cover"></image>
		</view>
		<view class="newss" v-else>
			<view class="news_title">{{content.title}}</view>
			<image v-if="content.cover && content.cover !== ''" :src="content.cover" mode="aspectFill"
				@click="videoMask = true">
			</image>
			<!-- <video :src="content.video" mode="" @click="videoMask = true"></video> -->
			<view class="small_text" v-if="content.cover">
				<view>{{content.format_date}}</view>
				<view class="looks">
					<u-icon name="eye"></u-icon><text style="margin-left: 5px;">{{content.clicks}}</text>
				</view>
			</view>
		</view>
		<u-popup v-model="videoMask" mode="center" @close="maskClose">
			<view class="mask_box" @close="maskClose">
				<video :src="content.video" controls @click.stop="" id="videos" :autoplay="videoMask"></video>
			</view>
		</u-popup>
		<!-- #ifdef H5 -->
		<u-popup v-model="goMiniAppMask" mode="center" border-radius="14">
			<view style="width: 570rpx;padding: 30rpx;">
				<view style="padding-bottom: 30rpx;border-bottom: 1px solid #eee;">
					{{isWeChat?`即将跳转到小程序${infoData.name}是否立即跳转？`:`即将打开微信，跳转到小程序${infoData.name}，是否立即跳转？`}}
				</view>
				<view style="display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;">
					<view style="height: 60rpx;width: 180rpx;display: flex;align-items: center;justify-content: center;
					color: #999;border: 1px solid #ccc;border-radius: 10rpx;" @click="goMiniAppMask = false">取消跳转</view>

					<wx-open-launch-weapp id="launch-btn" :username="infoData.applet.user_name" v-if="isWeChat"
						path="pages/index/startUp">
						<script type="text/wxtag-template">
							<style> 
									.item-menu-name-normal {
										font-weight: 400;
										color: #467DFE;
										text-align: center;
										overflow: hidden;
										text-overflow: ellipsis;
										display: -webkit-box;
										webkit-line-clamp: 2;
										webkit-box-orient: vertical;
									}
								</style>  
								<view style="height: {{getRealSize(60)}}px;width: {{getRealSize(180)}}px;display: flex;align-items: center;justify-content: center;color: #467DFE;border: 1px solid #467DFE;border-radius: {{getRealSize(10)}}px;font-size:{{getRealSize(28)}}px">
								立即跳转
								</view>	
							 </script>
					</wx-open-launch-weapp>

					<view style="height: 60rpx;width: 180rpx;display: flex;align-items: center;justify-content: center;
					color: #999;color: #467DFE;border: 1px solid #467DFE;border-radius: 10rpx;" v-else @click="goWeChat">立即跳转</view>
				</view>
			</view>
		</u-popup>
		<!-- #endif -->
	</view>
</template>

<script>
	// #ifdef H5
	let wx = require("jweixin-module")
	// #endif
	export default {
		props: ['content'],
		data() {
			return {
				videoMask: false,
				vedio_url: '',
				goMiniAppMask: false,
				infoData: JSON.parse(uni.getStorageSync('orgInfo')),
				isWeChat: uni.getStorageSync('isWeChat') ? uni.getStorageSync('isWeChat') : false,
			}
		},
		created() {},
		methods: {
			godetails(path, type) {
				// #ifdef MP
				if (this.content.cover_type !== 3) {
					this.$gourl('/pIndex/newsDetails?id=' + this.content.id)
				} else {
					this.$emit('url')
				}
				// #endif
				// #ifdef H5
				this.jumpMiniAppFun()
				// #endif
			},

			jumpMiniAppFun() {
				if (this.isWeChat) {
					this.$allApi.jsapiTicket({
						url: encodeURIComponent(location.href.split('#')[0])
					}).then(res => {
						var data = res.data;
						wx.config({
							debug: false, //调试模式
							appId: data.appId, //公众号的唯一标识
							timestamp: data.timestamp, // 生成签名的时间戳
							nonceStr: data.nonceStr, //生成签名的随机串
							signature: data.signature, //签名
							jsApiList: ["wx-open-launch-weapp"],
							openTagList: ["wx-open-launch-weapp"], //这一句是重点
						})
						wx.ready((e) => {
						})
						wx.error((e) => {
							_this.$util.showToast(e || '验证失败');
						})
						this.goMiniAppMask = true
					})
				} else {
					this.goMiniAppMask = true
				}
			},
			goWeChat() {
				this.goMiniAppMask = false
				this.$allApi.urlScheme({
					uid: uni.getStorageSync('uid')
				}).then(res => {
					window.location.href = res.data.openlink
				})
			},
			getRealSize(num) {
				return uni.upx2px(num)
			},
			maskClose(e) {
				console.log(e);
			},
		}
	}
</script>

<style scoped lang="scss">
	.mask_box {
		max-width: 690rpx;
		max-height: 80vh;
		display: flex;
		align-items: center;
		justify-content: center;

		video {
			width: 690rpx;
			min-height: 388.125rpx;
		}
	}

	.newss {
		background: #FBFBFB;
		border: 1px solid #EEEEEE;
		box-shadow: 0px 4rpx 8rpx 0px rgba(0, 16, 151, 0.0800);
		border-radius: 12rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		position: relative;

		image {
			width: 630rpx;
			height: 350rpx;
			border-radius: 10rpx;
		}

		video {
			width: 630rpx;
			height: 350rpx;
			border-radius: 10rpx;
		}

		.small_text {
			position: absolute;
			bottom: 36rpx;
			background: rgba(0, 0, 0, .5);
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 630rpx;
			height: 34rpx;
			left: 30rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			border-radius: 10rpx;
			font-size: 18rpx;
			color: #fff;
			margin-top: 30rpx;

			.looks {
				display: flex;
				align-items: center;
			}
		}

		.news_title {
			font-size: 28rpx;
			font-weight: bold;
			width: 630rpx;
			margin-bottom: 10rpx;
			text-align: left;
			color: #333333;
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden; //溢出内容隐藏
			text-overflow: ellipsis; //文本溢出部分用省略号表示
			display: -webkit-box; //特别显示模式
			-webkit-line-clamp: 2; //行数
			line-clamp: 2;
			-webkit-box-orient: vertical; //盒子中内容竖直排列
		}

		.news_text {
			width: 690rpx;
			flex: 1;
			padding-right: 30rpx;
			text-align: left;

			.news_description {
				font-size: 12px;
				color: #888;
				margin-top: 10px;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden; //溢出内容隐藏
				text-overflow: ellipsis; //文本溢出部分用省略号表示
				display: -webkit-box; //特别显示模式
				-webkit-line-clamp: 2; //行数
				line-clamp: 2;
				-webkit-box-orient: vertical; //盒子中内容竖直排列
			}


		}
	}

	.news {
		width: 690rpx;
		background: #FBFBFB;
		box-shadow: 0px 4rpx 8rpx 0px rgba(0, 16, 151, 0.0800);
		border-radius: 12rpx;
		padding: 30rpx;
		display: flex;
		// align-items: center;
		justify-content: space-between;
		margin-bottom: 20rpx;

		image {
			width: 240rpx;
			height: 180rpx;
			border-radius: 10rpx;
		}

		.news_text {
			flex: 1;
			padding-right: 30rpx;
			text-align: left;

			.news_title {
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden; //溢出内容隐藏
				text-overflow: ellipsis; //文本溢出部分用省略号表示
				display: -webkit-box; //特别显示模式
				-webkit-line-clamp: 2; //行数
				line-clamp: 2;
				-webkit-box-orient: vertical; //盒子中内容竖直排列
			}

			.fu_title {
				margin-top: 10rpx;
				font-size: 24rpx;
				height: 64rpx;
				color: #666;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden; //溢出内容隐藏
				text-overflow: ellipsis; //文本溢出部分用省略号表示
				display: -webkit-box; //特别显示模式
				-webkit-line-clamp: 2; //行数
				line-clamp: 2;
				-webkit-box-orient: vertical; //盒子中内容竖直排列
			}

			.news_description {
				font-size: 24rpx;
				color: #888;
				margin-top: 20rpx;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden; //溢出内容隐藏
				text-overflow: ellipsis; //文本溢出部分用省略号表示
				display: -webkit-box; //特别显示模式
				-webkit-line-clamp: 2; //行数
				line-clamp: 2;
				-webkit-box-orient: vertical; //盒子中内容竖直排列
			}

			.small_text {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 20rpx;
				margin-top: 30rpx;

				.time {
					font-size: 20rpx;
					border-radius: 6rpx;
					padding-right: 10rpx;
				}

				.looks {
					display: flex;
					align-items: center;
				}
			}
		}
	}
</style>
